﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Z2.Core
{
	public class Light
	{

		private Sprite m_light;
		private Rectangle m_shadowSize;
		private Color m_color;
		private Rectangle m_rect;

		public Light(string asset)
		{
			this.m_light = SpriteManager.Instance.LoadSprite(asset, 1, 1);
			this.LightSize = Rectangle.Empty;
			this.Color = Color.White;
			this.m_rect = new Rectangle();
			this.MultiplyLight = 1F;
		}

		public Rectangle LightSize
		{
			get { return this.m_shadowSize; }
			set 
			{ 
				this.m_shadowSize = value; 
				this.m_rect.Width = value.Width;
				this.m_rect.Height = value.Height;
			}
		}

		public float MultiplyLight { get; set; }

		public Color Color
		{
			get { return this.m_color; }
			set { this.m_color = value; }
		}

		public virtual void DrawLight(SpriteBatch batch, Vector2 position)
		{
			if (this.m_shadowSize.IsEmpty) return;
			this.m_rect.X = (int)(position.X);// + Camera.Instance.Position.X);
			this.m_rect.Y = (int)(position.Y);// + Camera.Instance.Position.Y);
			//Rectangle r = this.m_rect;
			//r.Width = Convert.ToInt32(Convert.ToSingle(r.Width) * MultiplyLight);
			//r.Height = Convert.ToInt32(Convert.ToSingle(r.Height) * MultiplyLight);
			batch.Draw(this.m_light.Texture, this.m_rect, this.m_color);
		}

		public virtual void DrawLight(SpriteBatch batch, Vector2 position, Sprite parentSprite)
		{
			if (this.m_shadowSize.IsEmpty) return;
			Rectangle r = LightSize;
            r.Width = Convert.ToInt32(Convert.ToSingle(LightSize.Width) * MultiplyLight);
            r.Height = Convert.ToInt32(Convert.ToSingle(LightSize.Height) * MultiplyLight);
			this.m_rect.X = (int)(position.X + ((parentSprite.FrameWidth - r.Width) / 2));
			this.m_rect.Y = (int)(position.Y + ((parentSprite.FrameHeight - r.Height ) / 2));
			this.m_rect.Width = r.Width;
			this.m_rect.Height = r.Height;
			batch.Draw(this.m_light.Texture, this.m_rect, this.m_color);
		}
	}
}
